<?php
class Admin_NewsCategoryController extends Zend_Controller_Action
{
	public function indexAction()
	{
		echo "TungViet";
		$model=new Admin_Model_NewsCategory();
		$this->view->pages=$model->lists();
	}
	public function createAction()
	{
		$form=new Admin_Form_Category();
		$form->init();
		$form->setMethod('post');
		if($this->getRequest()->isPost())
			{
				if($form->isValid($_POST))
				{
					$categoryName=$form->getValue('categoryName');
					$description=$form->getValue('description');
					$imageURL=$form->getValue('imageURL');
					$languageId=$form->getValue('languageId');
					$data=new Admin_Model_NewsCategory();
					$data->NewCategory($categoryName,$description,$imageURL,$languageId);
					$this->_redirect('admin/newscategory/index');
				}
			}
		$this->view->form=$form;
	}
	
	public function editAction()
	{
		$form=new Admin_Form_Category();
		$form->init();
		$id = $this->getRequest()->getParam('id');
		$form->setMethod('post');
		if($this->getRequest()->isPost())
		{
			if($form->isValid($_POST))
			{
				$categoryName=$form->getValue('categoryName');
				$description=$form->getValue('description');					
				$languageId=$form->getValue('languageId');
				$imageURL=$form->getValue('imageURL');					
				$data=new Admin_Model_NewsCategory();
				$data->updateCategory($id,$categoryName,$description,$languageId,$imageURL);
				$this->_redirect('admin/newscategory/index');
			}
		}
		else 
		{
			
			$model=new Admin_Model_NewsCategory();
			$data=$model->getCategory($id);
			$form=new Admin_Form_Category();
			$form->populate($data->toArray());
			$this->view->form=$form;
		}
	}
	public function deleteAction()
	{
		$id = $this->getRequest()->getParam('id');
		$model=new Admin_Model_NewsCategory();
		$model->deletePage($id);
		$this->_redirect('admin/newscategory');
	}	
	public function viewAction()
	{
		$this->view->id = $this->getRequest()->getParam('id');
	}
}